package cn.edu.neusoft.wuguangsheng.flowerimpression.fragment;


import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.UserAddAskActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.UserAnswerActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.UserAskActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.AskAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.AskBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetAskListModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class WenDaFragment extends BaseFragment implements View.OnClickListener {
    RecyclerView asklistview_rv;
    private List<AskBean> items;

    TextView asklistview_wdtw,asklistview_wdhd,asklistview_wytw;

    private boolean up = false;


    @Override
    void initView() {
        asklistview_rv = (RecyclerView)view.findViewById(R.id.asklistview_rv);

        asklistview_wdtw = (TextView)view.findViewById(R.id.asklistview_wdtw);
        asklistview_wdhd = (TextView)view.findViewById(R.id.asklistview_wdhd);
        asklistview_wytw = (TextView)view.findViewById(R.id.asklistview_wytw);

        GetAskListModel getAskListModel = new GetAskListModel();
        getAskListModel.getAskList(new ListListener<AskBean>() {
            @Override
            public void onResponse(List<AskBean> list) {
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext());
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                asklistview_rv.setLayoutManager(linearLayoutManager);
                items=list;
                AskAdapter askAdapter=new AskAdapter(getContext(),items,R.layout.ask_item);
                asklistview_rv.setAdapter(askAdapter);
                asklistview_rv.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFail(String msg) {

            }
        });

    }

    @Override
    void initEvent() {
        asklistview_wdtw.setOnClickListener(this);
        asklistview_wytw.setOnClickListener(this);
        asklistview_wdhd.setOnClickListener(this);

    }

    @Override
    void initDate() {

    }

    public WenDaFragment() {
        // Required empty public constructor
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.asklistview_wdtw:
                Intent intent = new Intent(getContext(),UserAskActivity.class);
                startActivity(intent);
                break;
            case R.id.asklistview_wdhd:
                Intent intent1 = new Intent(getContext(), UserAnswerActivity.class);
                startActivity(intent1);
                break;
            case R.id.asklistview_wytw:
                Intent intent2 = new Intent(getContext(), UserAddAskActivity.class);
                startActivity(intent2);
                break;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        setLayout_file(R.layout.fragment_wen_da);
        return super.onCreateView(inflater,container,savedInstanceState);
    }

    @Override
    public void onPause() {
        super.onPause();
        up = true;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (up) {
            initView();
            initEvent();
            initDate();
            up = false;
        }
    }


}
